package cn.wendellup.bootStrap.dao.impl;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import cn.wendellup.bootStrap.dao.contract.IFileDao;
import cn.wendellup.bootStrap.valueobject.entity.FileInfo;

@Repository
public class FileDaoImpl implements IFileDao{
	
	private static Logger logger = Logger.getLogger(FileDaoImpl.class);

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	private static final String STR_SELECT_FILE = " efs_id, app_id "
			+ " ,u_id ,file_name, file_type "
			+ " ,image_type, file_size, save_name "
			+ " ,is_save, is_delete, is_complete "
			+ " ,create_time, md5  ";
	
	@Override
	public FileInfo getFileInfoByEfsId(long efsId) {
		if(efsId<=0){
			return null;
		}
		String sqlOrginal = " select "
				+ STR_SELECT_FILE
				+ " from t_file where efs_id = %1$d "; 
		final String sql = String.format(sqlOrginal, efsId);
		logger.info(sql);
		FileInfo fileInfo = jdbcTemplate.queryForObject(sql, new FileInfo());
		return fileInfo;
	}

}
